package controllers;

import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import messages.*;
import ocsf.server.ConnectionToClient;
import messages.ComplaintMessage;

/**
 * the DB controller

 */
public class DBController {
/**
 * making the connection with DB by the specific case for each function
 * @param msg
 * @param client
 * @throws SQLException
 * @throws IOException
 */
	public DBController(Object msg, ConnectionToClient client1)  throws SQLException, IOException{
			
		
		ConnectionToClient client=new ConnectionToClient();
		
			client=client1;
			  String[] strMsg;
			  ClientController con=new ClientController(client);
			  
			  msg= msg.toString().substring(1, msg.toString().length()-1); // remove the [] from the msg by substring 
			  strMsg = msg.toString().split("[ , ] "); 	// remove the , from msg and splitting it to tiny str array parts  
			  
			  System.out.println(strMsg[0]);
			  System.out.println(strMsg[1]);             
			  System.out.println(strMsg[2]);
			  /*
			  switch(strMsg[0]){
			  
			  case("Login"): {
				  LoginMessage loginMsg= new LoginMessage(strMsg, client);
				  loginMsg.activation();
				  break;
			  }
			  
			  case("Complaint"): {
				  ComplaintMessage complaintMsg=new ComplaintMessage(strMsg,client);
				  complaintMsg.activationComplaint();
				  break;
			  					}
			  
			  case("Logout"): {
				  LogoutMessage logoutMsg=new LogoutMessage(strMsg,client);
				  logoutMsg.activate(strMsg[1]);
				  break;
			  }
		
			  
			  case("subscribingByCustomer"):{
				  SubscribingByCustomerMessage subCustomer=new SubscribingByCustomerMessage(strMsg,client);
				  subCustomer.activationSub();
				  break;
			  }
			  			  				
			  case("SearchPic"):{
				  SearchPicMessage searchmsg=new SearchPicMessage(strMsg,client);
				  searchmsg.activationSearch();
				  break;
			  	}
			  
			  
			 
			  
			  case("RequestUpdatePrices"):{
				  RequestUpdatePricesMessage requestMsg=new RequestUpdatePricesMessage(strMsg,client);
				  requestMsg.activateRequest();
				  break;				  
			  }
			  
			  case("UpdatePrices"): {
				  UpdatePricesMessage updateMsg=new UpdatePricesMessage(strMsg,client);
				  updateMsg.activateUpdate();
				  break;				  
			  }
			  
			  case ("ReplayToClient"):{
				  ReplayToClientMessage replayMsg=new ReplayToClientMessage(strMsg,client);
				  replayMsg.activateReplay();
				  break;
			  }
			
			
			  case ("SearchSamp"):{
				  SearchSampMessage searchsmp=new SearchSampMessage(strMsg,client);
				  searchsmp.activationSearchsamp();
				  break;
			  }
			
			  
			  
			  }*/
	}

}